<?php

namespace App\Services\MakeMoment;

use App\Models\User;
use App\Models\Moment;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class commentMoment
{
	protected $user;
	
	protected $moment;

	protected $content;
	
	public function __construct(User $user, Moment $moment,$content = null )
	{
		$this->user = $user;
		$this->moment = $moment;
		$this->content = $content;
	}
	
	
	
	protected function comment()
	{

		$moment = DB::transaction(function () {
			
			$data = [
				'moment_id'=>$this->moment->id,
				'content'=>$this->content
			];
			$moment = $this->user->momentComments()->create($data);
			return $moment;
		});
		
		return $moment;
	}
	
	public function create()
	{
		return $this->comment();
	}
}
